<?php
/**
 * 组件模块的控制器主要是用于前端组件ajax请求
 * 前端组件是指项目各模块之间可以共用的一些控件(例如产品类别选择框，项目部门联动选择框等)
 * 组件js代码放在public/static/js/app_widget下
 *
 * 仓库
 * @author shipanpan
 *
 */
class Widget_WarehouseController extends Controller_Base {
	/**
	 * 根据部门获取仓库
	 * @return [type] [description]
	 */
	public function getWarehouseByDepAction() {
		$departmentId = $this->_request->getParam('departmentId');
		$warehouseModel = new Application_Model_Warehouse;
		$warehouse = $warehouseModel->getWarehouseByIds($departmentId);
		exit($this->_helper->json($warehouse));
	}

	/**
	 * 获取仓库部门
	 * @return [type] [description]
	 */
	public function getWarehouseDepAction() {
		$db = Model_Db::getInstance();
		$warehouseDep = $db->fetchAll('select id,department_name from c_warehouse_dept where status=1');
		exit($this->_helper->json($warehouseDep));
	}

	/**
	 * 根据仓库名称获取仓库
	 * @return [type] [description]
	 */
	public function getByNameAction() {
		$warehouseName = $this->_request->getParam('warehouse_name');
		$db = Model_Db::getInstance();
		$select = $db->select();
		$select->from("c_warehouse", ['warehouse_code as id', 'warehouse_name as text'])->where("warehouse_name like ?", '%' . $warehouseName . '%');
		$warehouse = $db->fetchAll($select);
		exit($this->_helper->json($warehouse));
	}

	/**
	 * 根据仓库名称获取仓库
	 * @return [type] [description]
	 */
	public function getByCodeAction() {
		$warehouseCode = $this->_request->getParam('warehouse_code');
		$db = Model_Db::getInstance();
		$select = $db->select();
		$select->from("c_warehouse", ['warehouse_code as id', 'warehouse_name as text'])->where("warehouse_code =?", $warehouseCode);
		$warehouse = $db->fetchRow($select);
		exit($this->_helper->json($warehouse));
	}
}